package com.project.ServiceImp;


import com.alibaba.dubbo.config.annotation.Service;
import com.project.mapper.RegistrationDao;
import gz.RegistrationService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = RegistrationService.class)
@Component
@Transactional
public class RegistrationServiceImp implements RegistrationService {

    @Resource
    private RegistrationDao rd;


    /**
     * 查询出所有已挂号的患者信息且成功缴费
     * @param name
     * @param registration_status
     * @param startdate
     * @param enddate
     * @return
     */
    @Override
    public List<Map<String, Object>> find_Registration(String name,Integer registration_status,String startdate,String enddate) {
        Map<String,Object> map = new HashMap<>();
        map.put("name",name);
        map.put("status",registration_status);
        map.put("startdate",startdate);
        map.put("enddate",enddate);
        return rd.find_Registration(map);
    }


    /**
     * 点击作废按钮修改患者挂号状态为已作废
     * @param ids
     * @return
     */
    @Override
    public int updateStatus(Integer ids) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",ids);
        int i = rd.updateStatus(map);
        return i;
    }


    /**
     * 点击退款按钮获取患者退款信息
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Object>> Money_Back(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        return rd.Money_Back(map);
    }

    /**
     *退款成功修改患者状态
     * @param id
     * @return
     */
    @Override
    public int affirm_refund(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        int i= rd.affirm_refund(map);
        return i;
    }


    /**
     * 点击收费获取患者信息
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Object>> find_Registrations(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        return rd.find_Registrations(map);
    }


    /**
     *如收费成功则改变患者状态为待就诊
     * @param id
     * @return
     */
    @Override
    public int paymoney(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        int i= rd.paymoney(map);
        return i;
    }


    /**
     * 根据患者id查询出order_id
     * @param id
     * @return
     */
    @Override
    public int findOrderById(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        int i = rd.findOrderById(map);
        return i;
    }

    /**
     * 根据患者id查询出pkg-id
     * @param id
     * @return
     */
    @Override
    public int findPckById(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        int i = rd.findPckById(map);
        return i;
    }


    /**
     * 如退款成功则新增记录到表中
     * @param d
     * @param p
     * @param o
     * @return
     */
    @Override
    public int insert_refund(Double d, Integer p, Integer o) {
        Map<String,Object> map = new HashMap<>();
        map.put("money",d);
        map.put("pckid",p);
        map.put("orderid",o);
        int i = rd.insert_refund(map);
        return i;
    }


    /**
     *如收费成功则添加信息到收费总表中
     * @param p
     * @param r
     * @param o
     * @param m
     * @param c
     * @return
     */
    @Override
    public int insert_pkg(Integer p, Integer r, Integer o, Double m, String c) {
        Map<String,Object> map = new HashMap<>();
        map.put("money",m);
        map.put("patient_id",p);
        map.put("order_id",o);
        map.put("registration_id",r);
        map.put("case_code",c);
        return rd.insert_pkg(map);
    }


    /**
     * 查询出记录的id
     * @param code
     * @return
     */
    @Override
    public int select_pkgId(String code) {
        Map<String,Object> map = new HashMap<>();
        map.put("case_code",code);
        return rd.select_pkgId(map);
    }


    /**
     * 把记录添加到支付记录表中
     * @param k
     * @param m
     * @return
     */
    @Override
    public int insert_paylog(Integer k, Double m) {
        Map<String,Object> map = new HashMap<>();
        map.put("pkg_id",k);
        map.put("money",m);
        return rd.insert_paylog(map);
    }
}
